var xlsx = require('node-xlsx');
const fs = require('fs');
const path = require('path');

// 解析得到文档中的所有 sheet
var sheets = xlsx.parse(path.join(__dirname, `./lang.xlsx`));
const data = sheets[0].data;

const title = data.shift();

const result = {};

title.forEach((item) => (result[item] = {}));

const keys = Object.keys(result);

data.forEach((item) => {
  item.forEach((_item, i, arr) => {
    result[keys[i]][arr[0]] = _item;
  });
});

delete result.key;

for (let [key, value] of Object.entries(result)) {
  console.log('🚀 ~ file: index.js ~ line 29 ~ value', value);
  fs.writeFile(path.join(__dirname, `./${key}.json`), JSON.stringify(value), (err) => {
    if (err) {
      console.error(err);
      return;
    }
    console.log(key, '写入成功');
  });
}
